import { defineStore } from "pinia";
import { ref } from "vue";
import { login } from "@/public";
const useUserStore = defineStore("userStore", () => {
  const info = ref<UserInfo>();
  const apiLogin = async ({
    code = 0,
    callback,
    type,
  }: {
    code?: number;
    callback: Function;
    type?: string;
  }) => {
    if (code === -2 || !info.value?.id) {
      uni.removeStorageSync("userData");
      info.value = await login(callback);
      uni.setStorageSync("userData", info.value);
    }
    //非员工 不执行任何操作
    if ((info.value.team === 0 || info.value.type === 0) && type !== "login")
      return;
    callback();
  };
  return { info, apiLogin };
});
export default useUserStore;
